<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use session;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Crypt;

class loginController extends Controller
{
	public function login()
	{

		return view('admin.login.login');
	}
     
    public function doLogin(Request $request)
    {
        // return 111;
            //  echo Crypt::encrypt('111111');
            // die();
        $data = $request -> except('_token');

        $res = $data['code'] == session('milkcaptcha');
        if(!$res)
        {
        	return back() -> with(['info' => '验证码错误']);
        }else{
        	$res = DB::table('users') 
        	    -> where('email',$data['email'])
        	    -> first();
        	 	//dd($res);
        	if($res)
        	{
            $password = Crypt::decrypt($res -> password);
               if($password == $data['password'])
               {  
               	  if($res -> auth == 1)
               	  {
               	    session(['master' => $res]);
              	    return redirect('/admin/user/menu');
              	  }else{
                    return back() -> with(['info' => '你妹权利访问']);
                  }
               }else{
              	 return back() -> with(['info' => '密码错误']);
               }
            }else{
             return back() -> with(['info' => '邮箱错误']);
            }
        }

    }
    //清空session*********************************************8
    public function logout()
    {
      session() -> flush();//清空session;
      return redirect('/admin/login/login');
    }
    //忘记密码*****************************************************
  
}
